<?php

namespace api\modules\v1\controllers\marketing;

use Yii;
use api\controllers\OnAuthController;
use common\models\marketing\Tags;
use common\helpers\CommonHelper;

/**
 * Class TagsController
 * @package api\modules\v1\controllers\marketing
 */
class TagsController extends OnAuthController
{
    /**
     * @var Tags
     */
    public $modelClass = Tags::class;

    /**
     * @api {get} /v1/marketing/tags/index 标签列表
     * @apiName index
     * @apiGroup Tags
     */
    public function actionIndexTags()
    {
        $projectId = $this->projectId;

        // 查询结果
        $data = Yii::$app->services->marketingTags->getList($projectId);

        return $data;
    }

    /**
     * @api {post} /v1/marketing/tags/create 新增标签
     * @apiName create
     * @apiGroup Tags
     *
     * @apiParam {String} name              标签名称
     * @apiParam {Number} status            【1启用、0停用】
     */
    public function actionCreateTags()
    {
        $params = Yii::$app->request->post();
        $params['member_id'] = Yii::$app->user->identity->member_id;
        $params['project_id'] = $this->projectId;

        return Yii::$app->services->marketingTags->create($params);
    }

    /**
     * @api {post} /v1/marketing/tags/update 编辑标签
     * @apiName update
     * @apiGroup Tags
     *
     * @apiParam {Number} id                标签ID
     * @apiParam {Number} status            状态【0停用 1启用】
     */
    public function actionUpdateTags()
    {
        $params = Yii::$app->request->post();
        $params['member_id'] = Yii::$app->user->identity->member_id;
        $params['project_id'] = $this->projectId;
        return Yii::$app->services->marketingTags->update($params);
    }


    /**
     * @api {post} /v1/marketing/tags/update-status 编辑标签的状态
     * @apiName update-status
     * @apiGroup Tags
     *
     * @apiParam {Number} id                标签ID
     * @apiParam {Number} status            状态【0停用 1启用】
     */
    public function actionUpdateTagsStatus()
    {
        $id = Yii::$app->request->post('id');
        $status = Yii::$app->request->post('status');

        return Yii::$app->services->marketingTags->updateStatus($id, $status);
    }

    /**
     * @api {post} /v1/marketing/tags/delete 删除标签
     * @apiName delete
     * @apiGroup Tags
     *
     * @apiParam {Number} id                标签ID
     */
    public function actionDeleteTags()
    {
        $id = Yii::$app->request->post('id');

        return Yii::$app->services->marketingTags->delete($id);
    }


    /**
     * @api {post} /v1/marketing/tags/delete-tags-child 删除子标签
     * @apiName delete-tags-child
     * @apiGroup Tags
     *
     * @apiParam {Number} tags_id                子标签ID
     */
    public function actionDeleteTagsChild()
    {
        $tagsId = Yii::$app->request->post('tags_id');

        return Yii::$app->services->marketingTags->deleteTagsChild($tagsId);
    }

}